<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 用户
 * @author Administrator
 *
 */
class User extends MY_Controller {
	
	/**
	 * 修改密码
	 */
	public function index(){

		if($_POST){

			//表单验证
			$vConf = array(
						array('old', '原密码', 'required'),
						array('password', '新密码', 'required|min_length[6]|max_length[15]'),
						array('repassword', '确认密码', 'required')
					);
			$this->formDataValidation($vConf);

			$old = trim(post('old'));
			$password = trim(post('password'));
            $password = setPassword($password);


            //管理员信息
            $adminInfo = $this->mUser->getInfo($this->userAreaId);
            if( ! $adminInfo){
                $this->ajaxReturn(0,'管理员不存在');
            }

            if( ! $this->mUser->getInfoByAccountAndPassword($adminInfo['management_account'],setPassword($old))){
                $this->ajaxReturn(0,'原密码错误');
            }
            $data['password'] = $password;
            $data['addtime'] = time();
            if( ! $this->mUser->save($data, 0, $this->userAreaId)){

                $this->ajaxReturn(0,'保存失败');
            }

            $this->ajaxReturn(1, '修改成功');
		}
		
		$this->view('user','','validation');
	}
	

}
